//
//  DYZSelectCarsSeriesController.m
//  Demo
//
//  Created by 毕仲阳 on 16/8/18.
//  Copyright © 2016年 mycompany. All rights reserved.
//

#import "DYZSelectCarsSeriesController.h"
#import "Masonry.h"
#import "DYZSelectCarsTypeController.h"
static NSString *carSeriesID = @"carSeriesID";
@interface DYZSelectCarsSeriesController ()
@property(nonatomic,strong)NSArray *carsSeriers;
@end

@implementation DYZSelectCarsSeriesController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:carSeriesID];
    self.navigationItem.title = @"选择车系";
    NSArray *carsSeriies = @[@{@"name1":
                                   @[@{@"title":@"奔驰C级"},@{@"title":@"奔驰E级"},@{@"title":@"奔驰GLA级"},@{@"title":@"奔驰GLK级"}]},
                             @{@"name2":
                                   @[@{@"title":@"奔驰A级"},@{@"title":@"奔驰B级"},@{@"title":@"奔驰CLA级"},@{@"title":@"奔驰CLS级"},
                                     @{@"title":@"奔驰C级(进口)"},
                                     @{@"title":@"奔驰CLS级"},
                                     @{@"title":@"奔驰CLS级"}]}];
    self.carsSeriers = carsSeriies;
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return @"fffff";
    }else
    {
        return @"奔驰进口";
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,self.tableView.bounds.size.width , 30)];
    headerView.backgroundColor = [UIColor whiteColor];
    UILabel *headerLable = [[UILabel alloc]init];
    headerLable.font = [UIFont systemFontOfSize:14];
    headerLable.textColor = [UIColor grayColor];
    if (section == 0) {
        headerLable.text = @"北京奔驰";
    }else
    {
       headerLable.text = @"奔驰进口";
    }
    
    [headerView addSubview:headerLable];
    [headerLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(10);
        
    }];
    return headerView;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return self.carsSeriers.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    if (section == 0) {
        return [self.carsSeriers[section][@"name1"] count];
    }else
    {
        return [self.carsSeriers[section][@"name2"] count];
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:carSeriesID forIndexPath:indexPath];
    
    
//    if (indexPath.section == 0) {
//        cell.textLabel.text = self.carsSeriers[@"北京奔驰"];
//    }
    
    if (indexPath.section == 0) {
        NSArray *arr1 = self.carsSeriers[indexPath.section][@"name1"];
        
        cell.textLabel.text = arr1[indexPath.row][@"title"];
        
    }else
    {
        NSArray *arr2 = self.carsSeriers[indexPath.section][@"name2"];
        cell.textLabel.text = arr2[indexPath.row][@"title"];
    }
    
    
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DYZSelectCarsTypeController *ct = [[DYZSelectCarsTypeController alloc]init];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;
    //    [self.navigationController.navigationBar setBarTintColor:[UIColor darkGrayColor]];
    
    [self.navigationController.navigationBar setTintColor:[UIColor darkGrayColor]];
    [self.navigationController pushViewController:ct animated:YES];
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
